﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess {
    public class LoginLogRepository : DataProvider {
        /// <summary>
        /// write log
        /// </summary>
        /// <param name="SID">session id</param>
        /// <param name="partnerID">partner id</param>
        /// <returns></returns>
        public bool writeLog(String SID, int partnerID) {
            String sql = String.Format("INSERT INTO LoginLog(SID, PartnerID, Time) VALUES('{0}', {1}, '{2}')", SID, partnerID, DateTime.Now);
            if(this.executeQuery(sql) != -1)
                return true;

            return false;
        }

        public bool isLogin(String SID) {
            String sql = String.Format("SELECT COUNT(*) FROM LoginLog WHERE SID = '{0}'", SID);
            if (!this.executeScalar(sql).ToString().Equals("1")) { //isnot login or session expire
                return false;
            }
            return true;
        }
    }
}
